﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model.WXshopBuiness;
using Model.WXshopBuiness.Enum;
using Model.WeiXin.DTO;
using Services.WXshopBuiness;
using Xproject.Util;
using Model.Const;
using Services.Util;
using Model.Util;
using Model.Util.DTO;
using Model.Finance.DTO;
using Services.Finance;
using Model.ZXBuiness;
using Services.ZXBuiness;

namespace WeiXinProject.Controllers
{
    public class WalletController   : WXBaseController
    {
        WXOrderServices m_WXOrderServices;
        UserOperateServices m_UserOperateServices;
        UserCollectionServices m_userCollectionServices;
        AccountBalanceServices m_AccountBalanceServices;
        UserFenRunServices m_UserFenRunServices;
        public WalletController(UserFenRunServices mUserFenRunServices,AccountBalanceServices mAccountBalanceServices, WXOrderServices mWXOrderServices, UserOperateServices mUserOperateServices, UserCollectionServices muserCollectionServices)
        {
            m_WXOrderServices = mWXOrderServices;
            m_UserOperateServices = mUserOperateServices;
            m_userCollectionServices = muserCollectionServices;
            m_AccountBalanceServices = mAccountBalanceServices;
            m_UserFenRunServices = mUserFenRunServices;
        }

        // GET: Wallet
        public ActionResult Index()
        {
            ViewBag.JiFeng = this.CurrentUser.JiFeng;
            return View();
        }
        public ActionResult FenRunList(int state)
        {
            string userId = this.CurrentUser.UserID;
            var usermodel = this.CurrentUser;
            ViewBag.basicInfo = usermodel;
            ViewBag.state = state;
            return View();
        }

        public JsonResult GetMyFenRunList(int? index, int pagesize, int? state)
        {
            var jsonData = new Object();
            List<ZXUserFenRun> model = new List<ZXUserFenRun>();
            model = m_UserFenRunServices.GetMyFenRunList(index, pagesize, this.CurrentUser.ZX_UserID.Value,state);
            jsonData = new { Success = true, Data = model };
            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public JsonResult ApplyTiXian()
        {
            var jsonData = new Object();           
            bool success = false;
            string message = "";
            if (!this.CurrentUser.IsBindInfo)
            {
                jsonData = new { Success = false,Flag=1, Data = "您还没有提供微信或者支付宝或者银行卡，系统即将跳转到信息补充页面" };
                return Json(jsonData, JsonRequestBehavior.AllowGet);
            }
            string torderFengyunId = Request.Form["OrderFengyunId"];
            string tuserFenRunId = Request.Form["UserFenRunId"];
            long ZXuserid = this.CurrentUser.ZX_UserID.Value;
            long orderFengyunId = 0;
            long userFenRunId = 0;
            long.TryParse(torderFengyunId, out orderFengyunId);
            long.TryParse(tuserFenRunId, out userFenRunId);
            int result =m_UserFenRunServices.AddZXTiXianApply(userFenRunId, ZXuserid, orderFengyunId,this.CurrentUser.UserCode);
            if (result == 0)
            {
                message = "申请失败，联系管理员";
            }
            if (result == 1)
            {
                message = "系统收到您的提现请求，平台将于一个工作日将处理结果通知您，谢谢~";
                success = true;
            }
            if (result == 2)
            {
                message = "您已提交过申请，请耐心等待，平台会第一时间将处理结果通知您，谢谢~";
                success = true;
            }
            jsonData = new { Success = success, Data = message };             
            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }

        public ActionResult GetFenRunOrderInfo(long UserFenRunId)
        {
             ZXFenRunDetailModel model = m_UserFenRunServices.GetZXFenRunDetail(UserFenRunId);
            return View("~/Views/Wallet/FenRunDetail.cshtml", model);
        }
    }
}